package com.goodving.guli.activity;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;

import com.androidquery.AQuery;
import com.goodving.guli.R;
import com.goodving.guli.bt.BLEService;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.C0708b;
import com.goodving.guli.bt.C0715c;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.eventbus.EventDeviceBoundState;
import com.goodving.guli.bt.eventbus.EventScaleStatus;
import com.goodving.guli.bt.model.HwBatteryStatus;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.C1798h;
import com.goodving.guli.bt.profile.scale.C3843c;
import com.goodving.guli.bt.profile.scale.C3900g;
import com.goodving.guli.bt.profile.scale.C3907e;
import com.goodving.guli.bt.profile.scale.C3923a;
import com.goodving.guli.bt.profile.scale.FilterBleDevInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.HwConnStatus;
import com.goodving.guli.bt.profile.scale.XMBLEManager;
import com.goodving.guli.bt.profile.scale.XMLeScanCenter;
import com.goodving.guli.fragment.CalendarDailyFragment;
import com.goodving.guli.fragment.DiscoveryFragment;
import com.goodving.guli.fragment.HomeFragment;
import com.goodving.guli.fragment.MyHardwareFragment;
import com.goodving.guli.fragment.MySettingsFragment;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.utility.C1481u;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.utility.GuliBroadcastReceiver;
import com.goodving.guli.utility.GuliTabHostListener;
import com.goodving.guli.utility.LdlDate;
import com.goodving.guli.utility.SignInOnClickListener;
import com.goodving.guli.view.C3657a;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import de.greenrobot.event.EventBus;
import name.bagi.levente.pedometer.StepService;


/**
 * Created by Administrator on 2015-11-15.
 */
public class MainFragmentActivity extends FragmentActivity implements C1798h {
    public static String TAG;
    private static final int[] tabBtns;
    private static final String[] tabString;
    private final Class[] fragmentActivities;
    private AlertDialog f4020B;
    private FragmentTabHost mFragTabHost;
    private LayoutInflater mInflator;
    private View signInView;
    private AlphaAnimation f4024F;
    private View f4025G;
    private boolean f4026H;
    private final FragmentHandler mfragmentHandler;
//    private final int f4028J;
    public LdlDate mLdlDate;
    public String curTab;
    public Fragment mFragment;
    protected AQuery query;
    private final BroadcastReceiver mReceiver;
    public LdlDate f4030u;
    private boolean f8814C;
    private Handler f8828u;
    private BroadcastReceiver f8829w;
    private FilterBleDevInfo mFilterBleDevInfo;
    private boolean f8812A;
    private long f8821J = 0;

    public void m13593a(FilterBleDevInfo filterBleDevInfo) {
    }

    public void onScanedDevice(C3907e c3907e, FilterBleDevInfo filterBleDevInfo) {
        if (this.f8828u != null && Keeper.readWeightHwInfo().address.equalsIgnoreCase(c3907e.btDev.getAddress())) {
            this.f8828u.sendEmptyMessage(4114);
            if (!this.f8823L) {
                GuliLog.m12370d(TAG, "connectWeightDevice:" + c3907e);
                XMBLEManager.m25150a(c3907e.btDev, false);
                this.f8821J = System.currentTimeMillis();
                if (!this.f8828u.hasMessages(4112)) {
                    this.f8828u.sendEmptyMessageDelayed(4112, 60000);
                }
            }
            if (c3907e.scaleWeightInfo != null) {
                EventBus.getDefault().post(c3907e.scaleWeightInfo);
            }
        }
    }

    public void m13595b(FilterBleDevInfo filterBleDevInfo) {
    }

    class FragmentHandler extends Handler {
        final /* synthetic */ MainFragmentActivity mMainFragmentActivity;

        public FragmentHandler(MainFragmentActivity mainFragmentActivity) {
            this.mMainFragmentActivity = mainFragmentActivity;
        }

        public void handleMessage(Message message) {
            super.handleMessage(message);
            switch (message.what) {
                case Constants.STEPS_MSG /*1*/:
                    if (this.mMainFragmentActivity.mFragment instanceof HomeFragment) {
                        ((HomeFragment) this.mMainFragmentActivity.mFragment).updateData(message);
                    }
                default:
            }
        }
    }

    public MainFragmentActivity() {
        this.fragmentActivities = new Class[]{HomeFragment.class, MyHardwareFragment.class, DiscoveryFragment.class, MySettingsFragment.class};
//        this.mLdlDate = LdlDate.m8856a();
        this.curTab = tabString[0];
//        this.f4026H = false;
        this.mfragmentHandler = new FragmentHandler(this);
//        this.f4028J = 1;
        this.mReceiver = new GuliBroadcastReceiver(this);
    }

    static {
        TAG = MainFragmentActivity.class.getName();
        tabBtns = new int[]{R.drawable.tab_home_btn, R.drawable.tab_discovery_btn, R.drawable.tab_rank_btn, R.drawable.tab_more_btn};
        tabString = new String[]{"首页", "硬实力", "活力谷", "设置"};
    }

    private View getTabItemView(int i) {
        View inflate = this.mInflator.inflate(R.layout.tab_item_layout, null);
        ((ImageView) inflate.findViewById(R.id.imageview)).setImageResource(tabBtns[i]);
        return inflate;
    }

    private void initView() {
        this.mInflator = LayoutInflater.from(this);
        this.mFragTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        this.mFragTabHost.setup(this, getSupportFragmentManager(), R.id.content_frame);
        int length = this.fragmentActivities.length;
        for (int i = 0; i < length; i++) {
            this.mFragTabHost.addTab(this.mFragTabHost.newTabSpec(tabString[i]).setIndicator(getTabItemView(i)), this.fragmentActivities[i], null);
            this.mFragTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.color.white);
            this.mFragTabHost.getTabWidget().setStripEnabled(false);
        }
//        this.mFragTabHost.getTabWidget().getChildTabViewAt(2).setEnabled(false);
//        ((TabWidget) findViewById(16908307)).setShowDividers(0);
        this.mFragTabHost.setOnTabChangedListener(new GuliTabHostListener(this));
//        ((AQuery) this.query.id((int) R.id.tab_btn_add)).clicked(new GuliOnClickListener(this));
        this.signInView = findViewById(R.id.view_fake_sign_in_history);

        this.signInView.setOnClickListener(new SignInOnClickListener(this));
        this.f4025G = findViewById(R.id.rl_month_month);
    }

    public void m7828s() {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowHomeEnabled(false);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
//            actionBar.setCustomView(((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.actionbar_menu, null), new GridLayout.LayoutParams(-1, -1));
            actionBar.hide();
        }
    }


    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            mService = ((StepService.StepBinder)service).getService();

            mService.registerCallback(mCallback);
            mService.reloadSettings();

        }

        public void onServiceDisconnected(ComponentName className) {
            mService = null;
        }
    };

    // TODO: unite all into 1 type of message
    private StepService.ICallback mCallback = new StepService.ICallback() {
        public void stepsChanged(int value) {
            mfragmentHandler.sendMessage(mfragmentHandler.obtainMessage(Constants.STEPS_MSG, value, 0));
        }
        public void paceChanged(int value) {
            mfragmentHandler.sendMessage(mfragmentHandler.obtainMessage(Constants.PACE_MSG, value, 0));
        }
        public void distanceChanged(float value) {
            mfragmentHandler.sendMessage(mfragmentHandler.obtainMessage(Constants.DISTANCE_MSG, (int)(value*1000), 0));
        }
        public void speedChanged(float value) {
            mfragmentHandler.sendMessage(mfragmentHandler.obtainMessage(Constants.SPEED_MSG, (int) (value * 1000), 0));
        }
        public void caloriesChanged(float value) {
            mfragmentHandler.sendMessage(mfragmentHandler.obtainMessage(Constants.CALORIES_MSG, (int)(value), 0));
        }
    };

    private StepService mService;
    private long f8820I;

    private void startStepService() {

        Log.i(TAG, "[SERVICE] Start");
        C1481u.getContext().startService(new Intent(C1481u.getContext(), StepService.class));


    }

    private void bindStepService() {
        Log.i(TAG, "[SERVICE] Bind");
        C1481u.getContext().bindService(new Intent(C1481u.getContext(), StepService.class), mConnection, Context.BIND_AUTO_CREATE + Context.BIND_DEBUG_UNBIND);
    }

    private boolean f8831y = false;
    private boolean f8832z = false;
    private boolean f8822K = false;

    protected void m13651a() {
        GuliLog.m12370d(TAG, "=================onEnterInForeground=================");
        this.f8831y = false;
        this.f8822K = false;
        this.f8820I = System.currentTimeMillis();
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        bindStepService();
        XMBLEManager.startBleServiceForDevice(C1481u.getContext(), Keeper.readBraceletBtInfo().f19636b, Utils.m8093p());
//        m13626h();
        if (this.f8831y || this.f8832z) {
            m13651a();
        }
    }

    private void m13647w() {
        Object obj = null;
        Object obj2 = 1;
        NetworkInfo[] allNetworkInfo = ((ConnectivityManager) C1481u.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getAllNetworkInfo();
        int i = 0;
        while (i < allNetworkInfo.length) {
            if (allNetworkInfo[i].getType() != 1) {
                int i2;
                if (allNetworkInfo[i].getType() != 9) {
                    if (allNetworkInfo[i].getType() == 0 && allNetworkInfo[i].isConnected()) {
                        obj2 = null;
                        i2 = 1;
                        break;
                    }
                } else if (allNetworkInfo[i].isConnected()) {
                    obj2 = null;
                    i2 = 1;
                    break;
                }
            } else if (allNetworkInfo[i].isConnected()) {
                obj = 1;
                break;
            }
            i++;
        }
        obj2 = null;
//        if (obj != null) {
//            if (obj2 != null) {
//                m13648x();
//            }
//            m13598C();
//        }
    }
    class C1855u extends BroadcastReceiver {
        final /* synthetic */ MainFragmentActivity thisMainFragmentActivity;
        Message message;

        C1855u(MainFragmentActivity mainFragmentActivity) {
            this.thisMainFragmentActivity = mainFragmentActivity;
        }

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            GuliLog.tracePrintInfo("BaseSCActivity", action);
            if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
                this.thisMainFragmentActivity.m13647w();
            } else if (action.equals(BLEService.mStrConStatusChanged)) {
                message = new Message();
                message.what = 4116;
                message.obj = intent.getParcelableExtra(BLEService.mStrExtraParam);
                GuliLog.m12370d("BaseSCActivity", "INTENT_ACTION_CONN_STATUS_CHANGED......!!!" + message.obj);
                this.thisMainFragmentActivity.f8828u.sendMessage(message);
            } else if (action.equals(BLEService.mStrSyncDataStatusChanged)) {
//                HwSyncDataStatus hwSyncDataStatus = (HwSyncDataStatus) intent.getParcelableExtra(BLEService.f19424j);
//                if (hwSyncDataStatus.m25417d()) {
//                    if (hwSyncDataStatus.m25420g()) {
//                        if (hwSyncDataStatus.m25421h().m25105d()) {
//                            this.thisMainFragmentActivity.f8828u.sendEmptyMessage(4100);
//                        } else {
//                            this.thisMainFragmentActivity.f8828u.sendEmptyMessage(SyncWeightInfosToServerHandler.f197K);
//                        }
//                        C0668a.m8128a(this.thisMainFragmentActivity.f8830x, C0668a.ek, C0668a.dA);
//                    } else {
//                        C0668a.m8128a(this.thisMainFragmentActivity.f8830x, C0668a.ek, C0668a.dB);
//                    }
//                    this.thisMainFragmentActivity.m13649y();
//                }
//                EventBus.getDefault().postSticky(hwSyncDataStatus);
                return;
            }
            if ("android.bluetooth.adapter.action.STATE_CHANGED".equals(action)) {
                switch (intent.getIntExtra("android.bluetooth.adapter.extra.STATE", Integer.MIN_VALUE)) {
                    case 10 /*10*/:
                        this.thisMainFragmentActivity.f8828u.sendEmptyMessage(4102);
                        return;
                    case 12 /*12*/:
                        this.thisMainFragmentActivity.f8828u.sendEmptyMessage(4101);
                        return;
                    default:
                        return;
                }
            }
            if (BLEService.mStrDynamicStatusChanged.equals(action)) {
                this.thisMainFragmentActivity.f8828u.sendEmptyMessage(4103);
            } else if (action.equals(BLEService.mStrBatStatusChanged)) {
                HwBatteryStatus hwBatteryStatus = (HwBatteryStatus) intent.getParcelableExtra(BLEService.mStrExtraParam);
//                if (hwBatteryStatus.f19644e == 1) {
//                    this.thisMainFragmentActivity.m13612c(hwBatteryStatus.f19645f);
//                } else if (hwBatteryStatus.f19644e == 2) {
//                    this.thisMainFragmentActivity.m13645u();
//                } else if (hwBatteryStatus.f19644e == 3) {
//                    this.thisMainFragmentActivity.m13644t();
//                }
                EventBus.getDefault().post(hwBatteryStatus);
                return;
            }
            int intExtra;
            if (BLEService.mStrWeightConStatusChanged.equals(action)) {
                intExtra = intent.getIntExtra(BLEService.mStrExtraParam, -1);
                message = new Message();
                message.what = 4104;
                message.arg1 = intExtra;
                this.thisMainFragmentActivity.f8828u.sendMessage(message);
//                EventBus.getDefault().post(new C3917o(intExtra));
            } else if (action.equals("android.intent.action.CLOSE_SYSTEM_DIALOGS")) {
                action = intent.getStringExtra("reason");
                if (!TextUtils.isEmpty(action)) {
                    GuliLog.m12370d("BaseSCActivity", "ACTION_CLOSE_SYSTEM_DIALOGS:" + action);
                    if (action.equals("lock") || action.equals("homekey")) {
                        this.thisMainFragmentActivity.f8828u.sendEmptyMessage(4115);
                    }
                }
            } else if (action.equals(BLEService.mStrDevStatusChanged)) {
                intExtra = intent.getIntExtra(BLEService.mStrExtraParam, -1);
                // looks like it is for the ring
//                if (!Keeper.readPersonInfo().miliConfig.vibrate || !this.thisMainFragmentActivity.m13616d(intExtra)) {
//                }
            } else if (action.equals(BLEService.mStrWeightLowBat)) {
//                EventBus.getDefault().post(new EventWeightLowBattery());
            } else if (action.equals("android.intent.action.SCREEN_OFF")) {
                Keeper.setEnterAppTrace(3);
            }
        }
    }

    public boolean m13655a(Context context) {
        List runningTasks = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1);
        if (!(runningTasks == null || runningTasks.isEmpty())) {
            ComponentName componentName = ((ActivityManager.RunningTaskInfo) runningTasks.get(0)).topActivity;
            GuliLog.m12370d(TAG, "topActivity:" + componentName.flattenToString());
            if (!componentName.getPackageName().equals(context.getPackageName())) {
                return true;
            }
        }
        return false;
    }

    private boolean f8815D = true;
    static private XMLeScanCenter f8816E;
    private boolean f8823L = false;
    static {
        f8816E = XMLeScanCenter.getInstance();
    }

    private void m13622f(int i) {
        GuliLog.m12370d(TAG, "weight connect status:" + i);
        if (i == 1 || i == 0 || i == 4) {
            m13636m();
        } else if (i != 2 && i == 3) {
            this.f8823L = true;
            if (DeviceSource.hasBindWeight()) {
                this.f8828u.sendEmptyMessage(4105);
            }
            m13638n();
            GuliLog.m12370d(TAG, "removeWeightConnectFailedDynamic");
            this.f8828u.removeMessages(4112);
//            if (LuaUtil.getInstance(this.f8830x).m15967b()) {
//                this.f8828u.sendEmptyMessage(f8802l);
//            }
        }
    }
    private void m13638n() {
        GuliLog.m12370d(TAG, "stop scan for weight");
        if (this.mFilterBleDevInfo != null) {
            this.f8816E.m25373a(this.mFilterBleDevInfo);
            this.mFilterBleDevInfo = null;
        }
        this.f8828u.sendEmptyMessage(4114);
    }

    private void m13636m() {
        if (this.mFilterBleDevInfo == null) {
            this.mFilterBleDevInfo = new C3900g().setUUID(C3923a.y_).m25388a((C1798h) this).setTimeout(-1).create();
        }
        if (DeviceSource.hasBindWeight()) {
            if (((!m13655a(C1481u.getContext()) ? 1 : 0) != 0) | (this.f8815D != false)) {
                GuliLog.m12370d(TAG, "start scan for weight");
                this.f8815D = false;
                this.f8816E.startScan(C1481u.getContext(), this.mFilterBleDevInfo);
                this.f8828u.sendEmptyMessageDelayed(4113, 30000);
            }
        }
    }
    class C1853s extends Handler {
        final /* synthetic */ MainFragmentActivity handlerMainFragmentActivity;

        C1853s(MainFragmentActivity mainFragmentActivity) {
            this.handlerMainFragmentActivity = mainFragmentActivity;
        }

        public void handleMessage(Message message) {
            switch (message.what) {
                case 4098:
                    GuliLog.tracePrintInfo("BaseSCActivity", "MSG_LOAD_DATA_COMPLETE......................" + new Date().toString());
//                    EventBus.getDefault().post(new EventLoadDataComplete());
                    break;
                case 4099 /*4099*/:
//                    if (this.handlerMainFragmentActivity.f8827b.checkMiliFwUpgrade()) {
//                        new C3821i(new C1854t(this)).m9824f();
//                        return;
//                    }
//                    C3910h f = XMBLEManager.m25161f();
//                    if (f != null && f.m25440a()) {
//                        C3941i q = Utils.m8095q();
//                        if (q != null) {
//                            new C3936d().m25547a(q.f19893h, null);
//                        }
//                    }
                    break;
                case 4100:
//                    GuliLog.tracePrintInfo("BaseSCActivity", "shoes sync data complete");
//                    if (this.handlerMainFragmentActivity.f8827b.checkShoesFwUpgrade()) {
//                        this.handlerMainFragmentActivity.f8827b.upgrade(2);
//                    }
                    break;
                case 4101:
                    this.handlerMainFragmentActivity.m13636m();
                    if (DeviceSource.hasBindWeight() && this.handlerMainFragmentActivity.f8823L) {
//                        LuaUtil.getInstance(this.handlerMainFragmentActivity.f8830x).m15967b();
//                        this.handlerMainFragmentActivity.m13660b(false);
                    }
//                    if (DeviceSource.hasBindBracelet() || DeviceSource.hasBindShoesDevice()) {
//                        EventBus.getDefault().post(new EventBtOnOff(0));
//                    }
                    break;
                case 4102:
                    this.handlerMainFragmentActivity.m13638n();
//                    if (DeviceSource.hasBindBracelet() || DeviceSource.hasBindShoesDevice()) {
//                        EventBus.getDefault().post(new EventBtOnOff(1));
//                    }
                    if (DeviceSource.hasBindWeight()) {
//                        LuaUtil.getInstance(this.handlerMainFragmentActivity.f8830x).addWeightConnectFailedDynamic();
//                        this.handlerMainFragmentActivity.m13660b(false);
                    }
                    break;
                case 4103:
//                    this.handlerMainFragmentActivity.m13660b(false);
                    break;
                case 4104:
                    this.handlerMainFragmentActivity.m13622f(message.arg1);
                    break;
                case 4105:
//                    if (this.handlerMainFragmentActivity.f8827b.checkWeightFwUpgrade()) {
//                        this.handlerMainFragmentActivity.f8827b.upgrade(1);
//                    } else {
//                        this.handlerMainFragmentActivity.m13650z();
//                    }
                    break;
                case 4112:
                    GuliLog.m12370d("BaseSCActivity", "addWeightConnectFailedDynamic");
//                    LuaUtil.getInstance(this.handlerMainFragmentActivity.f8830x).addWeightConnectFailedDynamic();
//                    this.handlerMainFragmentActivity.m13660b(false);
                    break;
                case 4113:
                    this.handlerMainFragmentActivity.onWeightScanTimeout();
                    break;
                case 4114:
                    this.handlerMainFragmentActivity.onWeightFound();
                    break;
                case 4115:
                    this.handlerMainFragmentActivity.m13657b();
                    break;
                case 4116:
                    this.handlerMainFragmentActivity.m13605a((HwConnStatus) message.obj);
                    break;
                default:
                    break;
            }
            return;
        }
    }

    protected void m13657b() {
        GuliLog.m12370d(TAG, "=================onEnterInBackground=================");
        if (this.f8831y) {
            GuliLog.m12370d(TAG, "has onEnterInBackground,now return!!!");
            return;
        }
        this.f8831y = true;
        this.f8812A = false;
        this.f8823L = false;
        m13638n();
        if (0 == this.f8820I || this.f8821J <= this.f8820I) {
            GuliLog.tracePrintInfo(TAG, "connect device fail...");
//            C0668a.m8128a(this.f8830x, C0668a.fO, WeiboAuthException.DEFAULT_AUTH_ERROR_CODE);
        } else {
            GuliLog.tracePrintInfo(TAG, "connect device time " + this.f8821J + " mStartTime " + this.f8820I);
            C0668a.m8128a(C1481u.getContext(), C0668a.fO, C3657a.f18328f + (this.f8821J - this.f8820I));
        }
        this.f8820I = 0;
//        if (this.f8827b != null) {
//            this.f8827b.enableFwUpgrade();
//        }
    }

    private void m13625g(boolean z) {
        XMBLEManager.m25165j();
//        if (z || this.f8827b.checkMiliFwUpgrade() || System.currentTimeMillis() - Keeper.readSyncTime(0) > 120000) {
//            new C3839z(new C0639F(this.f8830x)).m9824f();
//        }
    }

    private void m13642r() {
        m13625g(false);
    }
    private void m13604a(C3843c c3843c) {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        boolean a = m13655a(C1481u.getContext());
        GuliLog.m12370d(TAG, "isEnterInBackground:" + a + ",isScreenOn:" + powerManager.isScreenOn());
        if (!a && powerManager.isScreenOn()) {
            if (c3843c.m25104c()) {
                HashMap hashMap = new HashMap();
                hashMap.put(C0715c.f3783y, XMBLEManager.m25160e().f19707a + C3657a.f18328f);
                hashMap.put(C0715c.f3784z, XMBLEManager.m25160e().f19708b.toString() + C3657a.f18328f);
                C0668a.m8131a(C1481u.getContext(), C0708b.af, hashMap);
                m13642r();
            }
//            else if (C3843c.SHOES.equals(c3843c)) {
//                m13656a(false);
//            }
        }
    }

    private void m13605a(HwConnStatus hwConnStatus) {
        GuliLog.m12370d(TAG, "HwConnStatus:" + hwConnStatus + ",type = " + hwConnStatus.m25399b());
        if (DeviceSource.hasBindShoesDevice() || DeviceSource.hasBindBracelet()) {
            EventBus.getDefault().postSticky(hwConnStatus);
            if (hwConnStatus.m25408k()) {
                m13604a(hwConnStatus.m25399b());
            }
        }
    }
    protected void onWeightScanTimeout() {
        GuliLog.tracePrintInfo(TAG, "onWeightScanTimeout");
        EventBus.getDefault().post(new EventScaleStatus(PersonInfo.INCOMING_CALL_DISABLE_BIT));
    }

    protected void onWeightFound() {
        GuliLog.tracePrintInfo(TAG, "onWeightFound");
        EventBus.getDefault().post(new EventScaleStatus(EventScaleStatus.SCALE_FOUNDED));
        this.f8828u.removeMessages(4113);
    }

    private void m13641q() {
        this.f8828u = new C1853s(this);
        this.f8829w = new C1855u(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        intentFilter.addAction(BLEService.mStrConStatusChanged);
        intentFilter.addAction(BLEService.mStrSyncDataStatusChanged);
        intentFilter.addAction(BLEService.mStrDynamicStatusChanged);
        intentFilter.addAction(BLEService.mStrBatStatusChanged);
        intentFilter.addAction(BLEService.mStrWeightConStatusChanged);
        intentFilter.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
        intentFilter.addAction("android.intent.action.CLOSE_SYSTEM_DIALOGS");
        intentFilter.addAction(BLEService.mStrDevStatusChanged);
        intentFilter.addAction(BLEService.mStrWeightLowBat);
        intentFilter.addAction("android.intent.action.SCREEN_OFF");
        registerReceiver(this.f8829w, intentFilter);
    }

    protected void onPause() {
        super.onPause();
        this.f8832z = false;
    }
    protected void onCreate(Bundle bundle) {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        super.onCreate(bundle);
        setContentView(R.layout.fragment_main);
        this.f8814C = (DeviceSource.hasBindBracelet() | DeviceSource.hasBindShoesDevice()) | DeviceSource.hasBindSensorHub();
        this.f8832z = true;

        m13641q();
//        m7828s();
//        MobclickAgent.onEvent(this, "welcome_home");
        this.query = new AQuery((Activity) this);
        startStepService();

        initView();

//        if (C1481u.m12099u()) {
//            m7815v();
//        }
//        m7814u();
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction("guli");
//        registerReceiver(this.mReceiver, intentFilter);
        EventBus.getDefault().register(this);

    }

    public void onEventMainThread(EventDeviceBoundState eventDeviceBoundState) {
        int i;
        GuliLog.m12370d(TAG, "EventDeviceBoundState:" + eventDeviceBoundState);
        int i2 = eventDeviceBoundState.mType;
        boolean z = eventDeviceBoundState.mState == 1;
        switch (i2) {
            case 0 /*0*/:
//                LuaEvent.getInstance(this.f8830x).deleteLuaOfStepAssociatedItem();
//                if (z) {
//                    EventBus.getDefault().postSticky(new HwConnStatus(XMBLEManager.m25158c() ? 6 : 4));
//                }
//                this.f8818G = z;
                i = 0;
                break;
            case 1 /*1*/:
                i = 1;
                break;
            case 3 /*3*/:
                i = 2;
//                if (!DeviceSource.hasBindBracelet()) {
//                    LuaEvent.getInstance(this.f8830x).deleteLuaOfStepAssociatedItem();
//                }
//                this.f8819H = z;
                break;
            default:
                i = 0;
                break;
        }
//        this.f8827b.setUpgradeState(i, true);
//        if (z) {
//            onDeviceBonded(i2);
//        } else {
//            m13658b(i2);
//        }
    }

    public void m7818a(Bundle bundle) {
        this.f4026H = true;
        this.f4025G.setVisibility(View.VISIBLE);
        FragmentTransaction a = getSupportFragmentManager().openTransaction();
        Fragment calendarDailyFragment = new CalendarDailyFragment();
        calendarDailyFragment.setArguments(bundle);
        a.add(R.id.rl_month_month, calendarDailyFragment);
        a.commit();
    }

    protected void onStop() {
        super.onStop();
        this.f8832z = false;
        if (m13655a((Context) this)) {
            this.f8828u.sendEmptyMessage(4115);
        }
//        if (this.f8826a != null) {
//            this.f8826a.m13249a();
//            this.f8826a = null;
//        }
    }
}
